
g_data = {"a": {"b": {'labels': [1, 2, 3, 4, 5], 'data': [4, 5, 6, 7, 8], 'c': {}}}}


def check_init_g_data(account_name, channel_name):
  if account_name not in g_data:
    g_data[account_name] = {}
  if channel_name not in g_data[account_name]:
    g_data[account_name][channel_name] = {'labels': [], 'data': []}


def add_data(account_name, channel_name, data):
  check_init_g_data(account_name, channel_name)
  g_data[account_name][channel_name]['labels'].append(data['labels'])
  g_data[account_name][channel_name]['data'].append(data['data'])


def clear_account_data(account_name):
  g_data.setdefault(account_name, {}).clear()


def clear_data(account_name, channel_name):
  check_init_g_data(account_name, channel_name)
  g_data[account_name][channel_name]['labels'].clear()
  g_data[account_name][channel_name]['data'].clear()


def get_data(account_name, channel_name):
  if account_name not in g_data or channel_name not in g_data[account_name]:
    return []

  return g_data[account_name][channel_name]


def get_data_struct():
  accounts = {}
  for k, v in g_data.items():
    accounts[k] = list(v.keys())
  return accounts
